package game.core.bullet
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import game.core.GameSystem;
	import game.core.IBullet;
	import game.core.IDataRender;
	import game.core.IDispose;
	import game.core.IGameObject;
	import game.core.util.DisplayUtil;

	public class Bullet extends Sprite implements IBullet,IGameObject,IDispose,IDataRender
	{
		public function Bullet()
		{
			super();
		}
		
		/**
		 * 创建子弹
		 */ 
		protected var bullet:*;
		
		public function createBullet():void {
		}
		public function shoot():void
		{
			this.dispose();
			this.createBullet();
			this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
		}
		
		protected function enterFrameHandler(event:Event):void {
			GameSystem.instance.hitTest(this);
			this.checkBoundary();
		}
		
		/**
		 * 检测是否应该需要消失,如果需要消失的话,那么执行这个方法
		 * 不同的内容可以重新写这个方法就可以了
		 */ 
		protected function checkBoundary():void{
			this.removeEventListener(Event.ENTER_FRAME,enterFrameHandler);
			GameSystem.instance.removeBullet(this);
		}
		
		public function dispose():void {
			DisplayUtil.removeAllChildren(this);
		}
		
		private var _data:Object;
		
		public function set data(value:Object):void {
			this._data = value;
		}
		
		public function get data():Object {
			return this._data;
		}
		
		private var _pause:Boolean;// 暂停的时候,其它的内容是不动的
		
		public function set pause(value:Boolean):void {
			if(this._pause != value){
				this._pause = value;
				if(value){
					this.removeEventListener(Event.ENTER_FRAME,enterFrameHandler);
				}else {
					if(!this.hasEventListener(Event.ENTER_FRAME)){
						this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
					}
				}
			}
		}
		
		public function get pause():Boolean {
			return this._pause;
		}
		
		private var _collidable:Boolean = false;// 是否可以碰撞,默认的同种类型的物体是可以碰撞的
		
		public function set collidable(value:Boolean):void {
			this._collidable = value;
		}
		
		public function get collidable():Boolean {
			return this._collidable;
		}
	}
}